﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineAuction
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                OnlineAuctionDataContext idc = new OnlineAuctionDataContext();
                this.DropDownListcategory.DataSource = idc.Categories.ToList();
                this.DropDownListcategory.DataTextField = "name";
                this.DropDownListcategory.DataValueField = "id_categories";
                this.DropDownListcategory.DataBind();
            }
        }

        protected void btnDaugia_Click(object sender, EventArgs e)
        {
            OnlineAuctionDataContext idc = new OnlineAuctionDataContext();
            var kt = idc.Items.Where(tk => tk.Equals(this.txttensanpham.ToString())).Count();
            Item it = new Item();
            it.item_title = this.txttensanpham.ToString();
            it.photo = this.FileUpload1.ToString();
            it.bid_start_price = Convert.ToInt32(this.txtgiasanpham.ToString());
            it.bid_startdate = Convert.ToDateTime(this.txtNgayBD.ToString());
            it.bid_enddate = Convert.ToDateTime(this.txtNgayKT.ToString());
            it.id_categories = Convert.ToInt32(this.DropDownListcategory.SelectedItem.Value);
            
            
            idc.Items.InsertOnSubmit(it);
            idc.SubmitChanges();
        }
    }
}